$(function() {
    //初始化
    Begin();
})
////////////--------------消息统计--------------------////////////
$.ajax({
    type: "post",
    url: "/msgStatistic/getMsRemainById",
    data:{token:sessionStorage.token},
    async: true,
    success: function(data) {
    	$('#xxzl').html(data.resultData.rmMsm);
    	$('#byxx').html(data.resultData.sendNum);
    	$('#bzxx').html(data.resultData.failMsg);
    	$('#jrxx').html(data.resultData.TimeMsg);
    }
});



////////////--------------统计图表--------------------////////////
var xAxisData = [],
    yAxisData = [],
    option,
    tabFirstClick;

//初始化
function Begin() {
    //面包屑
    new Vue().$mount('#crumbs');
    //获取整个菜单
    //new Vue().$mount('#menuL');
    //消息统计模块
    new Vue().$mount('#app');
    //饼图
    //左菜单滚动
    var oTop = $(".vany_authority").offset().top + 14;
    var sTop = 0;
    $(".vany_authority").scroll(function() {
        sTop = $(this).scrollTop();
        if(sTop >= oTop) {
            $("#menuL").css({
                "position": "fixed",
                "top": "60px"
            });
        } else {
            $("#menuL").css({
                "position": "absolute",
                "top": "0"
            });
        }
    });
    sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}



//消息模式统计
var subtext = 0,
    tw = 0,
    wz = 0,
    wl = 0;
$.ajax({
    type: "post",
    url: "/msgStatistic/getMsgPatternById",
    data: {
        token: sessionStorage.token
    },
    async: true,
    success: function(data) {
    	debugger
        subtext = data.resultData.xxzl;
        tw = data.resultData.tw;
        wz = data.resultData.wz;
        wl = data.resultData.wl;
        $($('#tableShow1 tr')[1].cells[1]).html(tw); //图文
        $($('#tableShow1 tr')[1].cells[2]).html((tw * 100 / subtext).toFixed(2) + '%');
        $($('#tableShow1 tr')[2].cells[1]).html(wz);
        $($('#tableShow1 tr')[2].cells[2]).html((wz * 100 / subtext).toFixed(2) + '%');
        $($('#tableShow1 tr')[3].cells[1]).html(wl);
        $($('#tableShow1 tr')[3].cells[2]).html((wl * 100 / subtext).toFixed(2) + '%');
        createOption(data.resultData.xxzl, data.resultData.tw, data.resultData.wz, data.resultData.wl);
    }
});
//消息渠道统计
$.ajax({
    type: "post",
    url: "/msgStatistic/getMsgChannelById",
    data: {
        token: sessionStorage.token
    },
    async: true,
    success: function(data) {
        subtext = data.resultData.xxzl;
        sms = data.resultData.sms;
        mail = data.resultData.mail;
        wechat = data.resultData.wechat;
        $($('#tableShow2 tr')[1].cells[1]).html(sms); //图文
        $($('#tableShow2 tr')[1].cells[2]).html((sms * 100 / subtext).toFixed(2) + '%');
        $($('#tableShow2 tr')[1].cells[3]).html(sms * 0.04);
        $($('#tableShow2 tr')[2].cells[1]).html(mail);
        $($('#tableShow2 tr')[2].cells[2]).html((mail * 100 / subtext).toFixed(2) + '%');
        $($('#tableShow2 tr')[2].cells[3]).html('0.00');
        $($('#tableShow2 tr')[3].cells[1]).html(wechat);
        $($('#tableShow2 tr')[3].cells[2]).html((wechat * 100 / subtext).toFixed(2) + '%');
        $($('#tableShow2 tr')[3].cells[3]).html('0.00');
        createOption1(subtext, sms, mail, wechat);
    }
});

function createOption(subtext, tw, wz, wl) {
    var myChart = echarts.init(document.getElementById('myChart'));
    option = {
        title: {
            text: '消息总数',
            subtext: subtext,
            left: 'center',
            top: '44%',
            itemGap: 5,
            textStyle: {
                color: '#141f1f',
                fontSize: 12
            },
            subtextStyle: {
                color: '#0072e6',
                fontSize: 18,
                fontWeight: 'bold'
            }
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            y: '30px',
            data: ['图文', '文本', '外链']
        },
        color: ['rgb(72,118,255)', 'rgb(255,182,193)', 'rgb(255,215,0)'],
        series: [{
            name: '消息',
            type: 'pie',
            radius: ['38%', '50%'],
            label: {
                normal: {
                    rich: {
                        b: {
                            fontSize: 12,
                            lineHeight: 20
                        }
                    }
                }
            },
            data: [{
                    value: tw,
                    name: '图文'
                },
                {
                    value: wz,
                    name: '文本'
                },
                {
                    value: wl,
                    name: '外链'
                }
            ]
        }]
    };
    myChart.setOption(option);
}

function createOption1(subtext, sms, mail, wechat) {
    var myChart1 = echarts.init(document.getElementById('myChart1'));
    option1 = {
        title: {
            text: '消息总数',
            subtext: subtext,
            left: 'center',
            top: '44%',
            itemGap: 5,
            textStyle: {
                color: '#141f1f',
                fontSize: 12
            },
            subtextStyle: {
                color: '#0072e6',
                fontSize: 18,
                fontWeight: 'bold'
            }
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            y: '30px',
            data: ['短信', '邮件', '企业号']
        },
        color: ['rgb(72,118,255)', 'rgb(255,182,193)', 'rgb(255,215,0)'],
        series: [{
            name: '消息',
            type: 'pie',
            radius: ['38%', '50%'],
            label: {
                normal: {
                    //formatter: '{b|{b}}\n{c}人',
                    rich: {
                        b: {
                            fontSize: 12,
                            lineHeight: 20
                        }
                    }
                }
            },
            data: [{
                    value: sms,
                    name: '短信'
                },
                {
                    value: mail,
                    name: '邮件'
                },
                {
                    value: wechat,
                    name: '企业号'
                }
            ]
        }]
    };
    myChart1.setOption(option1);
}
var Main = {
    data:function() {
        return {
            value6: ''
        };
    },
    methods: {
        pickTime:function(val) { //2017-09-11 - 2017-10-11
            $.ajax({
                type: "post",
                url: "/msgStatistic/getMsgPatternById",
                data: {
                    token: sessionStorage.token,
                    date: val
                },
                async: true,
                success: function(data) {
                    subtext = data.resultData.xxzl;
                    tw = data.resultData.tw;
                    wz = data.resultData.wz;
                    wl = data.resultData.wl;
                    $($('#tableShow1 tr')[1].cells[1]).html(tw); //图文
                    $($('#tableShow1 tr')[1].cells[2]).html((tw * 100 / subtext).toFixed(2) + '%');
                    $($('#tableShow1 tr')[2].cells[1]).html(wz);
                    $($('#tableShow1 tr')[2].cells[2]).html((wz * 100 / subtext).toFixed(2) + '%');
                    $($('#tableShow1 tr')[3].cells[1]).html(wl);
                    $($('#tableShow1 tr')[3].cells[2]).html((wl * 100 / subtext).toFixed(2) + '%');
                    createOption(data.resultData.xxzl, data.resultData.tw, data.resultData.wz, data.resultData.wl);
                }
            });
        },
        pickTime1:function(val) {
            //消息渠道统计
            $.ajax({
                type: "post",
                url: "/msgStatistic/getMsgChannelById",
                data: {
                    token: sessionStorage.token,
                    date: val
                },
                async: true,
                success: function(data) {
                    subtext = data.resultData.xxzl;
                    sms = data.resultData.sms;
                    mail = data.resultData.mail;
                    wechat = data.resultData.wechat;
                    $($('#tableShow2 tr')[1].cells[1]).html(sms); //图文
                    $($('#tableShow2 tr')[1].cells[2]).html((sms * 100 / subtext).toFixed(2) + '%');
                    $($('#tableShow2 tr')[1].cells[3]).html(sms * 0.04);
                    $($('#tableShow2 tr')[2].cells[1]).html(mail);
                    $($('#tableShow2 tr')[2].cells[2]).html((mail * 100 / subtext).toFixed(2) + '%');
                    $($('#tableShow2 tr')[2].cells[3]).html('0.00');
                    $($('#tableShow2 tr')[3].cells[1]).html(wechat);
                    $($('#tableShow2 tr')[3].cells[2]).html((wechat * 100 / subtext).toFixed(2) + '%');
                    $($('#tableShow2 tr')[3].cells[3]).html('0.00');
                    createOption1(subtext, sms, mail, wechat);
                }
            });
        }
    }
};
var Ctor = Vue.extend(Main);
new Ctor().$mount('#calendartool1');
new Ctor().$mount('#calendartool2');
